<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <input type="text" placeholder="姓名" v-model="emp.name">
    <input type="text" placeholder="工资" v-model="emp.salary">
    <input type="text" placeholder="工作" v-model="emp.job">
    <input type="button" value="添加" @click="f()">
    <table border="=1">
        <caption>员工列表</caption>
        <tr v-for="p in persons" align="center">
           <td>{{p.name}}</td>
           <td>{{p.salary}}</td>
           <td>{{p.job}}</td>
        </tr>
    </table>
</div>

<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>

<script>
    let v=new Vue({
        el:"body>div",
        data:{
            persons:[{name:'莫菲特',salary:"18888",job:"程序员"},{name:'周星驰',salary:"888888888",job:"演员"},{name:'张三',salary:"88888",job:"厨师"}],
            emp:{
                name:"",
                salary:"",
                job:""
            }

        },
        methods:{
            f(){
                //push:是js中数组里的添加方法
                // v.persons.push(v.emp)

                //此时emp对象的值发生改变和数组中的新对象是无关的,这种复制出来的和原对象无关的方式称为深拷贝(有关的是浅拷贝)
                v.persons.push(JSON.parse(JSON.stringify(v.emp)))
            }
        }
    })
</script>
</body>
</html>